<template>
    <div>
        <van-datetime-picker v-model="currentDate" type="date" title="选择年月日" :min-date="minDate" :max-date="maxDate"
            @confirm="onconfirm" @cancel="oncancel" />
    </div>
</template>

<script>
import dayjs from '@/utils/dayjs'
import { aditUserProfileAPI } from '@/api'
export default {
    model: {
        prop: 'birthday',
        event: 'updata:birthday'
    },
    props: {
        birthday: {
            type: String,
            required: true
        }
    },
    data() {
        return {
            minDate: new Date(1900, 0, 1),
            maxDate: new Date(),
            currentDate: new Date(this.birthday)
        }
    },
    methods: {
        async onconfirm() {
            const birthday = dayjs(this.currentDate).format('YYYY-MM-DD')
            await aditUserProfileAPI({
                birthday
            })
            this.$emit('close')
            this.$emit('updata:birthday', birthday)
        },
        oncancel() {
            this.$emit('close')
        }
    }
}
</script>

<style>

</style>